package p270jp.pxv.android.uploadNovel.presentation.activity;

import android.content.ComponentCallbacks;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.InputFilter;
import android.widget.TextView;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import com.google.android.material.appbar.MaterialToolbar;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import kotlin.NoWhenBranchMatchedException;
import p014ae.View$OnClickListenerC0050b;
import p022am.NovelBackupService;
import p047bg.C1124a;
import p064c6.Preconditions;
import p089d.C2424f;
import p090d0.C2428b;
import p134ei.AnalyticsAction;
import p134ei.PixivAnalytics;
import p138em.AbstractActivityC2955b;
import p189gn.AbstractC3435a;
import p189gn.AbstractC3446l;
import p215hm.TextChangedCounter;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.uploadNovel.presentation.view.PlainPasteEditText;
import p314lg.ActivityNovelEditorBinding;
import p325m0.MutabilityOwnership;
import p436q6.StringMerger;
import p467rd.subscribers;
import p503t.C6126e;
import p579vo.Qualifier;
import p593wc.AbstractC6902j;
import p603wm.AbstractC6949c;
import p603wm.Unit;
import p645yc.AndroidSchedulers;
import p671zc.Disposable;
import p680zl.NovelPostParameter;

/* compiled from: NovelEditorActivity.kt */
/* renamed from: jp.pxv.android.uploadNovel.presentation.activity.NovelEditorActivity */
/* loaded from: classes2.dex */
public final class NovelEditorActivity extends AbstractActivityC2955b {

    /* renamed from: D */
    public static final /* synthetic */ int f19397D;

    /* renamed from: C */
    public int f19400C;

    /* renamed from: v */
    public ActivityNovelEditorBinding f19401v;

    /* renamed from: w */
    public NovelPostParameter f19402w;

    /* renamed from: x */
    public int f19403x;

    /* renamed from: y */
    public final AbstractC6949c f19404y = Preconditions.m9802P(1, new C4347c(this, null, null));

    /* renamed from: z */
    public final AbstractC6949c f19405z = Preconditions.m9802P(1, new C4348d(this, null, null));

    /* renamed from: A */
    public final AbstractC6949c f19398A = Preconditions.m9801Q(new C4345a());

    /* renamed from: B */
    public Disposable f19399B = C2424f.m7739s();

    /* compiled from: NovelEditorActivity.kt */
    /* renamed from: jp.pxv.android.uploadNovel.presentation.activity.NovelEditorActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4345a extends Lambda implements AbstractC3435a<Integer> {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4345a() {
            super(0);
            NovelEditorActivity.this = r1;
        }

        @Override // p189gn.AbstractC3435a
        public Integer invoke() {
            Resources resources = NovelEditorActivity.this.getResources();
            int i = NovelEditorActivity.this.f19403x;
            if (i != 0) {
                return Integer.valueOf(resources.getInteger(C2428b.m7681a(i)) / 2);
            }
            MutabilityOwnership.m3737u("fieldType");
            throw null;
        }
    }

    /* compiled from: NovelEditorActivity.kt */
    /* renamed from: jp.pxv.android.uploadNovel.presentation.activity.NovelEditorActivity$b */
    /* loaded from: classes2.dex */
    public static final class C4346b extends Lambda implements AbstractC3446l<Integer, Unit> {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4346b() {
            super(1);
            NovelEditorActivity.this = r1;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(Integer num) {
            int intValue = num.intValue();
            NovelEditorActivity novelEditorActivity = NovelEditorActivity.this;
            novelEditorActivity.m4531U0(novelEditorActivity.f19400C + intValue);
            return Unit.f29503a;
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.uploadNovel.presentation.activity.NovelEditorActivity$c */
    /* loaded from: classes2.dex */
    public static final class C4347c extends Lambda implements AbstractC3435a<NovelBackupService> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19408a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4347c(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19408a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [am.a, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final NovelBackupService invoke() {
            return C1124a.m10173s(this.f19408a).f24118a.m920a().m621a(Reflection.m5499a(NovelBackupService.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.uploadNovel.presentation.activity.NovelEditorActivity$d */
    /* loaded from: classes2.dex */
    public static final class C4348d extends Lambda implements AbstractC3435a<PixivAnalytics> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19409a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4348d(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19409a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ei.e, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final PixivAnalytics invoke() {
            return C1124a.m10173s(this.f19409a).f24118a.m920a().m621a(Reflection.m5499a(PixivAnalytics.class), null, null);
        }
    }

    /* renamed from: S0 */
    public final void m4533S0() {
        NovelPostParameter bVar;
        int i = this.f19403x;
        if (i != 0) {
            NovelPostParameter bVar2 = this.f19402w;
            if (bVar2 != null) {
                ActivityNovelEditorBinding j0Var = this.f19401v;
                if (j0Var != null) {
                    String valueOf = String.valueOf(j0Var.f21712r.getText());
                    C6126e.m2298a(i);
                    int e = C6126e.m2294e(i);
                    if (e == 0) {
                        bVar = NovelPostParameter.m42a(bVar2, null, null, null, 0, valueOf, 0, 0, null, null, null, 1007);
                    } else if (e == 1) {
                        bVar = NovelPostParameter.m42a(bVar2, null, null, valueOf, 0, null, 0, 0, null, null, null, 1019);
                    } else {
                        throw new NoWhenBranchMatchedException();
                    }
                    this.f19402w = bVar;
                    NovelBackupService T0 = m4532T0();
                    NovelPostParameter bVar3 = this.f19402w;
                    if (bVar3 != null) {
                        T0.m12054d(bVar3);
                    } else {
                        MutabilityOwnership.m3737u("novelBackup");
                        throw null;
                    }
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                MutabilityOwnership.m3737u("novelBackup");
                throw null;
            }
        } else {
            MutabilityOwnership.m3737u("fieldType");
            throw null;
        }
    }

    /* renamed from: T0 */
    public final NovelBackupService m4532T0() {
        return (NovelBackupService) this.f19404y.getValue();
    }

    /* renamed from: U0 */
    public final void m4531U0(int i) {
        this.f19400C = i;
        ActivityNovelEditorBinding j0Var = this.f19401v;
        if (j0Var != null) {
            TextView textView = j0Var.f21711q;
            MutabilityOwnership.m3746l(textView, "binding.characterCounter");
            StringMerger.m2861a(textView, i, ((Number) this.f19398A.getValue()).intValue());
            return;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public void onBackPressed() {
        int i = this.f19403x;
        if (i != 0) {
            if (i == 1) {
                PixivAnalytics.m6529a((PixivAnalytics) this.f19405z.getValue(), 3, AnalyticsAction.UPLOAD_NOVEL_CONTENT_EDIT, null, 4);
            }
            this.f940i.m12030b();
            return;
        }
        MutabilityOwnership.m3737u("fieldType");
        throw null;
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        int i;
        int i2;
        String str;
        super.onCreate(bundle);
        String stringExtra = getIntent().getStringExtra("FIELD_TYPE_NAME");
        if (stringExtra != null) {
            this.f19403x = C2428b.m7676f(stringExtra);
            ViewDataBinding d = DataBindingUtil.m11369d(this, R.layout.activity_novel_editor);
            MutabilityOwnership.m3746l(d, "setContentView(this, R.l…ut.activity_novel_editor)");
            ActivityNovelEditorBinding j0Var = (ActivityNovelEditorBinding) d;
            this.f19401v = j0Var;
            MaterialToolbar materialToolbar = j0Var.f21713s;
            int i3 = this.f19403x;
            if (i3 != 0) {
                int e = C6126e.m2294e(i3);
                if (e == 0) {
                    i = R.string.novel_upload_property_text;
                } else if (e == 1) {
                    i = R.string.novel_upload_property_caption_title;
                } else {
                    throw new NoWhenBranchMatchedException();
                }
                C1124a.m10197Q(this, materialToolbar, i);
                ActivityNovelEditorBinding j0Var2 = this.f19401v;
                if (j0Var2 != null) {
                    j0Var2.f21712r.addTextChangedListener(new TextChangedCounter(new C4346b()));
                    ActivityNovelEditorBinding j0Var3 = this.f19401v;
                    if (j0Var3 != null) {
                        PlainPasteEditText plainPasteEditText = j0Var3.f21712r;
                        int i4 = this.f19403x;
                        if (i4 != 0) {
                            int e2 = C6126e.m2294e(i4);
                            if (e2 == 0) {
                                i2 = R.string.novel_upload_property_text_hint;
                            } else if (e2 == 1) {
                                i2 = R.string.novel_upload_property_caption_hint;
                            } else {
                                throw new NoWhenBranchMatchedException();
                            }
                            plainPasteEditText.setHint(i2);
                            ActivityNovelEditorBinding j0Var4 = this.f19401v;
                            if (j0Var4 != null) {
                                PlainPasteEditText plainPasteEditText2 = j0Var4.f21712r;
                                InputFilter.LengthFilter[] lengthFilterArr = new InputFilter.LengthFilter[1];
                                Resources resources = getResources();
                                int i5 = this.f19403x;
                                if (i5 != 0) {
                                    lengthFilterArr[0] = new InputFilter.LengthFilter(resources.getInteger(C2428b.m7681a(i5)));
                                    plainPasteEditText2.setFilters(lengthFilterArr);
                                    ActivityNovelEditorBinding j0Var5 = this.f19401v;
                                    if (j0Var5 != null) {
                                        j0Var5.f21713s.setNavigationOnClickListener(new View$OnClickListenerC0050b(this, 19));
                                        NovelPostParameter c = m4532T0().m12055c();
                                        if (c != null) {
                                            this.f19402w = c;
                                            int i6 = this.f19403x;
                                            if (i6 != 0) {
                                                int e3 = C6126e.m2294e(i6);
                                                if (e3 == 0) {
                                                    str = c.f31493e;
                                                } else if (e3 == 1) {
                                                    str = c.f31491c;
                                                } else {
                                                    throw new NoWhenBranchMatchedException();
                                                }
                                                ActivityNovelEditorBinding j0Var6 = this.f19401v;
                                                if (j0Var6 != null) {
                                                    j0Var6.f21712r.setText(str);
                                                    m4531U0(C2424f.m7742p(str));
                                                    return;
                                                }
                                                MutabilityOwnership.m3737u("binding");
                                                throw null;
                                            }
                                            MutabilityOwnership.m3737u("fieldType");
                                            throw null;
                                        }
                                        throw new IllegalStateException();
                                    }
                                    MutabilityOwnership.m3737u("binding");
                                    throw null;
                                }
                                MutabilityOwnership.m3737u("fieldType");
                                throw null;
                            }
                            MutabilityOwnership.m3737u("binding");
                            throw null;
                        }
                        MutabilityOwnership.m3737u("fieldType");
                        throw null;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("fieldType");
            throw null;
        }
        throw new IllegalStateException();
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onPause() {
        super.onPause();
        this.f19399B.mo78a();
        m4533S0();
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        this.f19399B.mo78a();
        Objects.requireNonNull(m4532T0());
        this.f19399B = subscribers.m2589g(AbstractC6902j.m988m(60, 60, TimeUnit.SECONDS).m986o(AndroidSchedulers.m334a()), null, null, new p138em.NovelEditorActivity(this), 3);
    }
}
